package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.base.result.ResponseVo;
import com.atguigu.srb.core.pojo.entity.vo.*;
import com.atguigu.srb.core.service.BorrowInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-10-11
 */
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {

    @Resource
    BorrowInfoService borrowInfoService;
    @ApiOperation("查询借款列表")
    @GetMapping("{pageNum}/{pageSize}")
    public ResponseVo list(@PathVariable("pageNum")Integer pageNum,
                           @PathVariable("pageSize")Integer pageSize,
                                   BorrowInfoSearchVO borrowInfoSearchVO){
        Page<BorrowInfoVO> page = borrowInfoService
                .getBorrowInfoVOs2(borrowInfoSearchVO,pageNum,pageSize);
        return ResponseVo.ok().data("page",page);
    }

    @ApiOperation("查询借款详情")
    @GetMapping("{id}")
    public ResponseVo boorowInfoDetail(@PathVariable("id")Long id){
        BorrowInfoDetailVO borrowInfoDetailVO = borrowInfoService.getBorrowInfoDetail(id);
        return ResponseVo.ok().data("item",borrowInfoDetailVO);
    }

    @ApiOperation("借款审批")
    @PutMapping ("approval")
    public ResponseVo approval(@RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO){
        borrowInfoService.approval(borrowInfoApprovalVO);
        return ResponseVo.ok();
    }
}

